package com.itycu.server.service.business;

import java.util.List;
import com.itycu.server.utils.DateUtils;
import com.itycu.server.dto.business.PraProduceDto;
import com.itycu.server.core.AbstractService;
import com.itycu.server.utils.SecurityUtils;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.itycu.server.mapper.business.PraProduceMapper;
import com.itycu.server.domain.business.PraProduce;

/**
 * 生产管理Service业务层处理
 *
 * @author itycu
 * @date 2025-02-25
 */
@Service("praProduceService")
public class PraProduceService extends AbstractService<PraProduce> {
    @Resource
    private PraProduceMapper praProduceMapper;

    /**
     * 查询生产管理列表
     *
     * @param praProduce 生产管理
     * @return 生产管理
     */
    public List<PraProduceDto> list(PraProduce praProduce) {
        praProduce.setOrderByClause("id desc");
        return praProduceMapper.listByCondition(praProduce);
    }

    /**
     * 根据id获取生产管理详细信息
     */
    @Override
    public PraProduceDto findById(Long id) {
        return praProduceMapper.findById(id);
    }

    /**
     * 保存生产管理
     *
     * @param praProduce 生产管理
     * @return 结果
     */
    @Override
    public int save(PraProduce praProduce) {
        int count;
        if (praProduce.getId() == null) {
            praProduce.setCreateTime(DateUtils.getNowDate());
            praProduce.setCreateBy(SecurityUtils.getUserId());
            count = super.save(praProduce);
        } else {
            praProduce.setUpdateTime(DateUtils.getNowDate());
            praProduce.setUpdateBy(SecurityUtils.getUserId());
            count = super.update(praProduce);
        }
        return count;
    }
}
